package com.ykh.controller;
import com.ykh.pojo.po.User;
import com.ykh.pojo.vo.ErrorCode;
import com.ykh.pojo.vo.Result;
import com.ykh.service.FocusedService;
import com.ykh.util.UserThreadLocal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2023-06-08
 * Time: 13:32
 */
@RestController
@RequestMapping("focused")
public class FocusedController {

    @Autowired
    FocusedService focusedService;
    /**
     * 关注用户接口
     * @param account 被关注的用户id
     * @return
     */
    @PostMapping("/add")
    public Result focusUser(@RequestParam("id") String account) {
        User user = UserThreadLocal.get();
        if(user == null){
            return Result.fail(ErrorCode.NO_LOGIN.getCode(), ErrorCode.NO_LOGIN.getMsg());
        }
        return focusedService.focusUser(account, user);
    }

    /**
     * 取消关注用户接口
     * @param account 被关注的用户id
     * @return
     */
    @PostMapping("cancel")
    public Result cancelFocus(@RequestParam("id") String account) {
        User user = UserThreadLocal.get();
        if(user == null){
            return Result.fail(ErrorCode.NO_LOGIN.getCode(), ErrorCode.NO_LOGIN.getMsg());
        }
        return focusedService.cancelFocus(account, user);
    }

    /**
     * 判断是否关注过该用户
     * @param account 被关注的用户id
     * @return
     */
    @PostMapping("/isFocus")
    public Result isFocus(@RequestParam("id")String account) {
        User user = UserThreadLocal.get();
        if(user == null){
            return Result.fail(ErrorCode.NO_LOGIN.getCode(), ErrorCode.NO_LOGIN.getMsg());
        }
        return focusedService.isFocus(account, user);
    }

    /**
     * 获取自己关注的用户信息列表
     * @return
     */
    @PostMapping("getMyFocusList")
    public Result getMyFocusList() {
        User user = UserThreadLocal.get();
        if(user == null){
            return Result.fail(ErrorCode.NO_LOGIN.getCode(), ErrorCode.NO_LOGIN.getMsg());
        }
        return focusedService.getMyFocusList(user);
    }

    /**
     * 获取自己的粉丝列表
     * @return
     */
    @PostMapping("getFocusedList")
    public Result getFocusedList() {
        User user = UserThreadLocal.get();
        if(user == null){
            return Result.fail(ErrorCode.NO_LOGIN.getCode(), ErrorCode.NO_LOGIN.getMsg());
        }
        return focusedService.getFocusedList(user);
    }

}
